/// 私聊消息数据模型
/// 记录两个用户之间的单聊消息
class WhisperEssence {
  final String id;
  final String senderId;
  final String receiverId;
  final String messageType; // 'text' 或 'call_failed'
  final String content;
  final bool isRead;
  final DateTime createTime;

  WhisperEssence({
    required this.id,
    required this.senderId,
    required this.receiverId,
    required this.messageType,
    required this.content,
    required this.isRead,
    required this.createTime,
  });

  /// 从Map创建WhisperEssence
  factory WhisperEssence.fromMap(Map<String, dynamic> map) {
    return WhisperEssence(
      id: map['id'] as String,
      senderId: map['senderId'] as String,
      receiverId: map['receiverId'] as String,
      messageType: map['messageType'] as String,
      content: map['content'] as String,
      isRead: map['isRead'] as bool,
      createTime: DateTime.parse(map['createTime'] as String),
    );
  }

  /// 转换为Map
  Map<String, dynamic> toMap() {
    return {
      'id': id,
      'senderId': senderId,
      'receiverId': receiverId,
      'messageType': messageType,
      'content': content,
      'isRead': isRead,
      'createTime': createTime.toIso8601String(),
    };
  }

  /// 复制并修改部分属性
  WhisperEssence copyWith({
    String? id,
    String? senderId,
    String? receiverId,
    String? messageType,
    String? content,
    bool? isRead,
    DateTime? createTime,
  }) {
    return WhisperEssence(
      id: id ?? this.id,
      senderId: senderId ?? this.senderId,
      receiverId: receiverId ?? this.receiverId,
      messageType: messageType ?? this.messageType,
      content: content ?? this.content,
      isRead: isRead ?? this.isRead,
      createTime: createTime ?? this.createTime,
    );
  }
}
